<?php

class Admin_SubjectsController extends Zend_Controller_Action
{
	public function init()
	{
		/* Initialize action controller here */
	}
	public function indexAction()
	{
		$pp = new Admin_Model_Subjects();
		$row = $pp->getList();
		$this->view->grid=$row;
		
		$form = new Admin_Form_Subjects();
		$form->setAction('/admin/subjects/store');
		$this->view->form_sub=$form;
		// action body
	}
	public function storeAction()
	{
		$form = new Admin_Form_Subjects();
		$this->view->form=$form;
		
		if($this->getRequest()->isPost()){
			$formData=$this->getRequest()->getPost();
			if($form->isValid($formData)){
				$name=$form->getValue('name');
				$id = $form->getValue('subject_id');
				$obj=new Admin_Model_Subjects();
				if(!empty($id)){
					$obj->editSubject(array('name'=>$name));
				}else{
					$obj->addSubject(array('name'=>$name));
				}
				$this->_helper->redirector('index');
			}
			else{
				$form->populate($formData);
			}
		}
	}
	public function addAction()
	{
		
	}
	public function editAction()
	{
		
	}
	public function deleteAction()
	{
		$id = $this->getRequest()->getParam('subject');
		
		if(!empty($id)){
			$obj=new Admin_Model_Subjects();
			$obj->deleteSubject($id);
		}
		$this->_helper->redirector('index');
		// action body
	}
	public function changeAction()
	{
	
		// action body
	}
}

